<template>
	<view class="courses-page">
		<z-paging ref="paging" v-model="dataList" @query="queryList" :height="scrollViewHeight+'px'">
			<view slot="top">
				<view class="tab-list">
					<view :class="tabsIndex==index?'tab-item active':'tab-item'" v-for="(item,index) in tabsList"
						:key="index" @click="tabsChange(index)">{{item.name}}</view>
				</view>
			</view>
			<view class="courses-list">
				<view class="courses-item" v-for="(item,index) in dataList" :key="index">
					<image :src="item.image" class="item-left"></image>
					<view class="item-center">
						<view class="courses-title">{{item.name}}</view>
						<!-- <view class="courses-surplus">剩余课时：{{item.surplus_sum}}</view> -->
						<view class="courses-time">预约日期：{{item.day}}</view>
						<view class="courses-time">预约时间：{{item.time}}</view>
					</view>
					<view class="item-right">
						<view class="button button2" v-if="item.status==0"
							@click="$Tips('/pages/order/orderVerification?pre_id='+item.id)">
							核销码</view>
						<view class="button button1" v-if="item.status==0" @click="cancelReservation(item)">取消预约</view>
						<view class="button button3" v-if="item.status==1">已核销</view>
						<view class="button button3" v-if="item.status==2">已取消</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				card_id: null,
				tabsList: [{
					name: '全部',
					status: '',
				}, {
					name: '待核销',
					status: '0',
				}, {
					name: '已核销',
					status: '1',
				}],
				tabsIndex: 0,
				dataList: [],

			}
		},
		onLoad(options) {
			if (options && options.card_id) {
				this.card_id = options.card_id
			}
		},
		onShow() {
			this.refreshList()
		},
		methods: {
			cancelReservation(item) {
				this.$Api.courses.cancelReservation({
					pre_id: item.id,
				}).then(res => {
					this.$Toast('取消成功')
					this.refreshList()
				})
			},
			tabsChange(index) {
				this.tabsIndex = index
				this.refreshList()
			},
			refreshList() {
				this.$refs.paging.scrollToTop()
				this.$refs.paging.refresh();
			},
			queryList(pageNo, pageSize) {
				this.$Api.user.courseReservationRecord({
					page: pageNo,
					limit: pageSize,
					card_id: this.card_id,
					status: this.tabsList[this.tabsIndex].status
				}).then(res => {
					this.$refs.paging.complete(res.data.data);
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.courses-page {
		width: 100%;
		min-height: 100vh;
		background: #F6F6F8;

		.tab-list {
			min-height: 86rpx;
			margin: 20rpx 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.tab-item {
				text-align: center;
				width: 216rpx;
				height: 88rpx;
				line-height: 88rpx;
				box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);
				border-radius: 200rpx;
				font-weight: bold;
				font-size: 32rpx;
			}

			.active {
				background: #A3C616;
				color: #ffffff;
			}
		}

		.courses-list {
			background-color: #F7F8FA;

			.courses-item {
				margin: 0 30rpx 20rpx;
				border-radius: 28rpx;
				padding: 20rpx 22rpx;
				display: flex;
				align-items: center;
				background: #ffffff;

				.item-left {
					width: 156rpx;
					height: 156rpx;
					margin-right: 20rpx;
				}

				.item-center {
					flex: 1;

					.courses-title {
						font-weight: bold;
						font-size: 32rpx;
						width: 300rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.courses-time {
						font-size: 26rpx;
						color: #565656;
						margin-top: 20rpx;
					}

					.courses-surplus {
						font-size: 26rpx;
						color: #565656;
						margin-top: 16rpx;
					}
				}

				.item-right {
					min-width: 200rpx;
					min-height: 156rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					align-items: flex-end;
					.button {
						width: 156rpx;
						height: 56rpx;
						font-weight: bold;
						font-size: 28rpx;
						line-height: 56rpx;
						text-align: center;
						border-radius: 44rpx;
					}
					
					.button1 {
						color: #FFB900;
						background: #FFF8E5;
						border: 1rpx solid #FFB900;
					}
					
					.button2 {
						color: #A3C616;
						background: #FBFFED;
						border: 1rpx solid #A3C616;
					}
					
					.button3 {
						color: #DADADA;
						background: #F9F9F9;
						border: 1rpx solid #E5E5E5;
					}
				}
			}
		}
	}
</style>